<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>

    <div id="app">


        <input v-model="todoName" type="text" >
        <button @click="add">添加任务</button>

        <ul>
          
            <li v-for="(item,index) in list" :key="item.id">
                <span>{{index+1}}</span>

                <span>{{item.name}}</span>

                <button @click="del(item.id)">删除</button>

            </li>

        </ul>
    </div>
    <!-- //添加功能 
    // 1.通过v-model绑定输入框   实时获取表单元素的内容
    //2.点击按钮，进行新增，本质上是往数组的最前面加 unshift -->
    <script>
        const app = new Vue({
            el: "#app",
            data: {
                todoName: '',

                list: [{
                        id: 1,
                        name: '跑步'
                    },
                    {
                        id: 2,
                        name: '早起'
                    },
                    {
                        id: 3,
                        name: '跳绳'
                    },

                ]
            },
            methods: {
                del(id) {
                    // console.log(id);
                    this.list = this.list.filter(item => item.id !== id)

                }


            }
        })
    </script>

</body>

</html>